import React,{ Component } from 'react';
import './welcomeLag.scss';
import './labelMy.scss';
import '../index/index.scss';
import { message } from 'antd';
import { editSignature } from 'api/user.js';
export default class LabelMy extends Component{
	constructor (props) {
		super(props)
		this.state={
			value: props.location.state.personal_signature,
			sum: 0
		}
	}
	goBack () { //返回上一级
		this.props.history.goBack()
	}
	handleChange (e) { //限制字数
		if(this.state.value.length < 150){
			let value1=e.target.value.slice(0,150);
			this.setState({
				value:value1
			},()=>{
				this.setState({
					sum:this.state.value.length
				})
			})
		} else{
			let value1=e.target.value.slice(0,150);
			this.setState({
				value: value1
			},()=>{
				this.setState({
					sum:this.state.value.length
				})
			})
		}
	}
	_editSignature(){
		editSignature({
			signature_content: this.state.value
		}).then(res => {
			if(res.code === 1){
				message.success('编辑成功！', 3 , this.props.history.push(`${window.baseUrl}/user`))
			}
		})
	}
	componentDidMount(){
		document.title = '个性签名'
		this.setState({
			sum:this.state.value.length
		})
	}
	render(){
		return(
			<div className="labelMy welcomeLag">
				{/*<div className="title">
					<div onClick={this.goBack.bind(this)}><i className="glyphicon glyphicon-left"></i></div>
					<div>个性签名</div>
					<div></div>
				</div>*/}
				<textarea className="labelMy_textArea" placeholder="个人描述或座右铭" onChange={this.handleChange.bind(this)} value={this.state.value}/>
				<span className="perfectCard_sum">{this.state.sum}/150</span>
				<div className="perfectCard_button" onClick={this._editSignature.bind(this)}>保存</div>
			</div>
		)
	}
}